# Maintainer: Paul Mattal <paul@archlinux.org>

pkgname=hdparm
pkgver=9.62
pkgrel=1
pkgdesc="A shell utility for manipulating Linux IDE drive/driver parameters"
arch=(x86_64)
depends=('glibc')
optdepends=('sh: required by idectl and ultrabayd')
source=(https://downloads.sourceforge.net/sourceforge/hdparm/${pkgname}-${pkgver}.tar.gz
        wiper.sh.2_6.max-ranges.patch pass-ldflags.patch)
license=('BSD')
url="https://sourceforge.net/projects/hdparm/"
optdepends=('bash: for wiper.sh script')
options=('emptydirs')
sha512sums=('ac6c4d285d081ecd8c7b231192a5a0fc268d934eeeb59794ae9a9db01ecbdd0afa0cade6ed42a1fd26ad543c52a3b380ac4f1b679992d167becb4ed6251fd369'
            'ddb9eff6e4c0b67da72104a9ddcb6fde2b6ad543174e56a7e065453beb88f4c16b977718b1db4beaed41aff477a0ed955303172d019efbe9eacef2a397f27499'
            '4103276304a858a9540ce173f22c5eb64cadac36b5cd38d9396d63fa721a579e16d4d0f84e3c627d0620c42815c437abf14c9657fdb1a28e8263a52a0bb26c4f')

prepare() {
  cd ${pkgname}-${pkgver}
  # Fix Range input/output error when wiping Intel G2 and OCZ drives
  patch -Np1 -i "$srcdir"/wiper.sh.2_6.max-ranges.patch
  # Enable FULL RELRO
  patch -Np1 -i "$srcdir"/pass-ldflags.patch
}

build() {
  cd ${pkgname}-${pkgver}
  make
}

package() {
  cd ${pkgname}-${pkgver}
  # install
  mkdir -p "${pkgdir}"/usr/bin
  make DESTDIR="${pkgdir}" sbindir=/usr/bin install
  install -m755 contrib/idectl "${pkgdir}"/usr/bin
  install -m755 contrib/ultrabayd "${pkgdir}"/usr/bin

  install -D -m 0644 $srcdir/$pkgname-$pkgver/wiper/README.txt "$pkgdir"/usr/share/doc/wiper/README.txt
  install -D -m 0755 $srcdir/$pkgname-$pkgver/wiper/wiper.sh "$pkgdir"/usr/bin/wiper.sh

  #install license file
  install -D -m 644 LICENSE.TXT "$pkgdir"/usr/share/licenses/hdparm/LICENSE.TXT
}
